package ChatRoom;

import java.net.InetAddress;

public class TestInetAddress {
    public static void main(String[] args) {
        try {
            InetAddress localAddress = InetAddress.getLocalHost(); // 获取本地 IP 地址
            InetAddress remoteAddress = InetAddress.getByName("www.baidu.com"); // 获取百度的 IP 地址

            System.out.println("本机的IP地址:" + localAddress.getHostAddress());
            System.out.println("百度的IP地址:" + remoteAddress.getHostAddress());
            System.out.println("3秒是否可达:" + remoteAddress.isReachable(3000)); // 测试 3 秒内是否可达
            System.out.println("百度的主机名为:" + remoteAddress.getHostName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}